package problem03_06;

import java.util.LinkedList;
import java.util.List;

//面试题03.06动物收容所
//https://leetcode.cn/problems/animal-shelter-lcci/?envType=problem-list-v2&envId=queue

class AnimalShelf {

    List<Integer> catList;
    List<Integer> dogList;

    public AnimalShelf() {
        catList = new LinkedList<>();
        dogList = new LinkedList<>();
    }
    
    public void enqueue(int[] animal) {
        if(animal[1] == 0) {
            catList.add(animal[0]);
        }else {
            dogList.add(animal[0]);
        }
    }
    
    public int[] dequeueAny() {
        if(catList.size() > 0 && dogList.size() > 0) {
            if(catList.get(0) < dogList.get(0)) {
                return dequeueCat();
            }else {
                return dequeueDog();
            }
        }else if(catList.size() > 0) {
            return dequeueCat();
        }else if(dogList.size() > 0) {
            return dequeueDog();
        }
        return new int[]{-1,-1};
    }
    
    public int[] dequeueDog() {
        if(dogList.size() == 0) {
            return new int[]{-1,-1};
        }
        int t = dogList.get(0);
        dogList.remove(0);
        return new int[]{t, 1};
    }
    
    public int[] dequeueCat() {
        if(catList.size() == 0) {
            return new int[]{-1,-1};
        }
        int t = catList.get(0);
        catList.remove(0);
        return new int[]{t, 0};
    }
}

/**
 * Your AnimalShelf object will be instantiated and called as such:
 * AnimalShelf obj = new AnimalShelf();
 * obj.enqueue(animal);
 * int[] param_2 = obj.dequeueAny();
 * int[] param_3 = obj.dequeueDog();
 * int[] param_4 = obj.dequeueCat();
 */